var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperList: [],
    limit: 5,
    newslist: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.guanggao();
    this.list(8)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  guanggao() {
    var that = this;
		var setid = app.globalData.cityCode;
		app.core('get', 'get_advert/site_id/' + setid +'', '', (res) => {
      console.log(res)
      that.setData({
        swiperList: res.data
      })
    })
  },
  list(num) {
    var that = this;
    var n = that.data.limit;
    var list = that.data.newslist;
		var setid = app.globalData.cityCode;
		app.core('get', 'get_hot_news/site_id/' + setid +'/limit/' + num + '', "", (res => {
      console.log(res)
      var arrs = res.data;
      for (var i = 0; i < arrs.length; i++) {
        var time = that.getLocalTime(arrs[i].createTime)
        arrs[i].createTime = time;
        list.push(arrs[i])
      }

      var x = list;

      that.setData({
        newslist: x ,
        limit: num + 6
      })

    }))

  },
  //获取资讯列表
  getLocalTime(date) {
    // return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
    var date = new Date(date * 1000);//如果date为13位不需要乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    return Y + M + D + h + m + s;


  }, // 转换时间戳
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(111)
    var that = this;
    var num = that.data.limit;
    
    console.log(num);

    that.list(num)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})